﻿Imports System.ComponentModel
Imports System.Configuration.Install
Imports System.IO



Public Class InstallerBabel

    Public Sub New()
        MyBase.New()

        'El Diseñador de componentes requiere esta llamada.
        InitializeComponent()

        'Agregue el código de inicialización después de llamar a InitializeComponent

    End Sub

    Public Overrides Sub Install(ByVal stateSaver As System.Collections.IDictionary)
        MyBase.Install(stateSaver)

        Dim sFolderStart As String = ""
        Dim sFolderBabel As String = ""

        Try
            sFolderStart = Environment.GetFolderPath(Environment.SpecialFolder.Startup)
        Catch ex As Exception

        End Try
        Try
            sFolderBabel = Me.Context.Parameters.Item("FolderProg").ToString
        Catch ex As Exception

        End Try

        Try
            Dim FolderStart As DirectoryInfo = New DirectoryInfo(sFolderStart)
            Dim FolderBabel As DirectoryInfo = New DirectoryInfo(sFolderBabel)

            Try

                File.Copy(Path.Combine(FolderBabel.FullName, "babel.lnk"), Path.Combine(FolderStart.FullName, "babel.lnk"), True)

                'MsgBox("Copied " & vbCrLf & "'" & FolderBabel.FullName & "babel.lnk'" & vbCrLf & " to" & vbCrLf & "'" & FolderStart.FullName & "babel.lnk'")

            Catch ex As Exception

                MsgBox("Cant find or copy '" & FolderBabel.FullName & "babel.lnk' to folder '" & FolderStart.FullName & "'" & vbCrLf & ex.ToString)

            End Try

        Catch ex As Exception

            MsgBox("Cant operate with folders to set a copy of link Babel at startup, proceed manually is needed." & vbCrLf & "Folder startup: " & sFolderStart & vbCrLf & "Folder babel: " & sFolderBabel & vbCrLf & ex.ToString)

        End Try

    End Sub

    Public Overrides Sub Uninstall(ByVal savedState As System.Collections.IDictionary)

        Try

            Try

                File.Delete(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Startup), "babel.lnk"))

            Catch ex As Exception

            End Try


        Catch ex As Exception

        End Try

        MyBase.Uninstall(savedState)


    End Sub

    Private Sub InstallerBabel_AfterInstall(ByVal sender As Object, ByVal e As System.Configuration.Install.InstallEventArgs) Handles Me.AfterInstall

        Try
            Shell(Path.Combine(Me.Context.Parameters.Item("FolderProg").ToString, "BABEL.EXE"), AppWinStyle.NormalFocus, False)
        Catch ex As Exception

        End Try

    End Sub
End Class
